package com.cysion.study.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.cysion.study.ktbox.base.BaseAdapter
import com.cysion.study.ktbox.base.BaseViewHolder
import com.cysion.other._setOnClickListener
import com.cysion.study.R
import com.cysion.study.entity.ApprovalEntity
import kotlinx.android.synthetic.main.item_pending.view.*

class PendingAdapter(mEntities: MutableList<ApprovalEntity>, mContext: Context) :
    BaseAdapter<ApprovalEntity>(mEntities, mContext) {
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BaseViewHolder<ApprovalEntity> {

        return ProMoneyHolder(
            LayoutInflater.from(mContext).inflate(R.layout.item_pending, parent, false)
        )
    }
    class ProMoneyHolder(itemView: View) : BaseViewHolder<ApprovalEntity>(itemView) {
        override fun fillData(obj: ApprovalEntity, position: Int) {
            itemView?.apply {
                //                itemView.tv_data.text=
                //0.请假 1.报销 2.调休
                if (obj.type == "0") {
                    tv_qj.text="请假"
                }else if (obj.type == "1") {
                    tv_qj.text = "报销"
                } else {
                    tv_qj.text = "调休"
                }
                tv_name.text=obj.name
                tv_submit_time.text=obj.createTime
                tv_start_time.text=obj.startTime
                tv_end_time.text=obj.endTime
                tv_data.text=obj.totalTime
                tv_content.text=obj.remark

                tv_appro_num.text= "审批人("+obj.examines?.size+")"
               /* Glide.with(context)
                    .load(obj.examines?.get(0)?.url)
                    .apply(RequestOptions.placeholderOf(R.mipmap.place_holder_big))
                    .apply(RequestOptions.bitmapTransform(RoundTransform(6)))
                    .into(iv_head)*/
                if (obj.examines.size > 0) {
                    tv_approver.text= obj.examines[0].stName
                }
                tv_copy_num.text= "抄送人("+obj.copys?.size+")"
                if (obj.copys.size > 0) {
                    tv_copyer.text=obj.copys?.get(0)?.stName
                }



                tv_detail._setOnClickListener {
                    mOnTypeClickListener?.invoke(obj, position, -1)//-1 点击审批明细
                }
                var content = et_yj.text.toString().trim()
                obj.remark = content
                tv_agree._setOnClickListener {
//                    context.ShowToast("同意")
                    //当通知需要确认时必填 1.同意 2.拒绝
                    mOnTypeClickListener?.invoke(obj, position, 1)

                }
                tv_refuse._setOnClickListener {
//                    context.ShowToast("拒绝")
                    //当通知需要确认时必填 1.同意 2.拒绝
                    mOnTypeClickListener?.invoke(obj, position, 2)
                }
            }

        }

    }

}



